import http from '../../apis/api.js';
import util from '../../utils/util.js';
import config from '../../config.js';
const app = getApp();
let self;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: null,
    tel: config.tel,
    ownNo:'',
    totalOwnHomePage:null,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    self = this;
    wx.getStorage({
      key: 'loginInfo',
      success: function (res) {
        util.getUserInfo().then(res => {
          self.setData({
            userInfo: res.userInfo
          })
        })
      },
      fail() {
        wx.navigateTo({
          url: `/pages/login/login`,
        })
      }
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    wx.getStorage({
      key: 'landlordInfo',
      success: function (res) {
        self.data.ownNo = res.data.ownNo;
        http.totalOwnHomePage({ ownNo: self.data.ownNo }).then(res=>{
          self.data.totalOwnHomePage = res.data;
          self.setData({
            ownNo: self.data.ownNo,
            totalOwnHomePage: self.data.totalOwnHomePage
          })
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  contactUs(e) {
    let phone = e.currentTarget.dataset.phone;
    wx.makePhoneCall({
      phoneNumber: phone
    })
  },
  goShouce(){
    wx.navigateTo({
      url: `/pages/agreement/agreement?url=${encodeURIComponent('https://ms.maishe.live/applyLandlordAtt.html')}&type='user'`
    })
  }
})